package com.bootdo.blog.dao;

import com.bootdo.blog.domain.AppearanceDO;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
/**
 * 
 * 
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2021-03-07 10:38:31
 */
@Mapper
public interface AppearanceMapper {

	@Select("select `appearance_id`, `product_name`, `playing_time`, `playing_number`, `playing_price`, `specification`, `customer_store_name`, `customer_name`, `customer_telephone`, `inspection_id`, `operator_id` from tb_appearance where appearance_id = #{id}")
	AppearanceDO get(Integer appearanceId);
	
	@Select("<script>" +
	"select * from tb_appearance " + 
			"<where>" + 
		  		  "<if test=\"appearanceId != null and appearanceId != ''\">"+ "and appearance_id = #{appearanceId} " + "</if>" + 
		  		  "<if test=\"productName != null and productName != ''\">"+ "and product_name = #{productName} " + "</if>" + 
		  		  "<if test=\"playingTime != null and playingTime != ''\">"+ "and playing_time = #{playingTime} " + "</if>" + 
		  		  "<if test=\"playingNumber != null and playingNumber != ''\">"+ "and playing_number = #{playingNumber} " + "</if>" + 
		  		  "<if test=\"playingPrice != null and playingPrice != ''\">"+ "and playing_price = #{playingPrice} " + "</if>" + 
		  		  "<if test=\"specification != null and specification != ''\">"+ "and specification = #{specification} " + "</if>" + 
		  		  "<if test=\"customerStoreName != null and customerStoreName != ''\">"+ "and customer_store_name = #{customerStoreName} " + "</if>" + 
		  		  "<if test=\"customerName != null and customerName != ''\">"+ "and customer_name = #{customerName} " + "</if>" + 
		  		  "<if test=\"customerTelephone != null and customerTelephone != ''\">"+ "and customer_telephone = #{customerTelephone} " + "</if>" + 
		  		  "<if test=\"inspectionId != null and inspectionId != ''\">"+ "and inspection_id = #{inspectionId} " + "</if>" + 
		  		  "<if test=\"operatorId != null and operatorId != ''\">"+ "and operator_id = #{operatorId} " + "</if>" + 
		  			"</where>"+ 
			" <choose>" + 
	            "<when test=\"sort != null and sort.trim() != ''\">" + 
	                "order by ${sort} ${order}" + 
	            "</when>" + 
				"<otherwise>" + 
	                "order by appearance_id desc" + 
				"</otherwise>" + 
	        "</choose>"+
			"<if test=\"offset != null and limit != null\">"+
			"limit #{offset}, #{limit}" + 
			"</if>"+
			"</script>")
	List<AppearanceDO> list(Map<String, Object> map);
	
	@Select("<script>" +
	"select count(*) from tb_appearance " + 
			"<where>" + 
		  		  "<if test=\"appearanceId != null and appearanceId != ''\">"+ "and appearance_id = #{appearanceId} " + "</if>" + 
		  		  "<if test=\"productName != null and productName != ''\">"+ "and product_name = #{productName} " + "</if>" + 
		  		  "<if test=\"playingTime != null and playingTime != ''\">"+ "and playing_time = #{playingTime} " + "</if>" + 
		  		  "<if test=\"playingNumber != null and playingNumber != ''\">"+ "and playing_number = #{playingNumber} " + "</if>" + 
		  		  "<if test=\"playingPrice != null and playingPrice != ''\">"+ "and playing_price = #{playingPrice} " + "</if>" + 
		  		  "<if test=\"specification != null and specification != ''\">"+ "and specification = #{specification} " + "</if>" + 
		  		  "<if test=\"customerStoreName != null and customerStoreName != ''\">"+ "and customer_store_name = #{customerStoreName} " + "</if>" + 
		  		  "<if test=\"customerName != null and customerName != ''\">"+ "and customer_name = #{customerName} " + "</if>" + 
		  		  "<if test=\"customerTelephone != null and customerTelephone != ''\">"+ "and customer_telephone = #{customerTelephone} " + "</if>" + 
		  		  "<if test=\"inspectionId != null and inspectionId != ''\">"+ "and inspection_id = #{inspectionId} " + "</if>" + 
		  		  "<if test=\"operatorId != null and operatorId != ''\">"+ "and operator_id = #{operatorId} " + "</if>" + 
		  			"</where>"+ 
			"</script>")
	int count(Map<String, Object> map);
	
	@Insert("insert into tb_appearance (`product_name`, `playing_time`, `playing_number`, `playing_price`, `specification`, `customer_store_name`, `customer_name`, `customer_telephone`, `inspection_id`, `operator_id`)"
	+ "values (#{productName}, #{playingTime}, #{playingNumber}, #{playingPrice}, #{specification}, #{customerStoreName}, #{customerName}, #{customerTelephone}, #{inspectionId}, #{operatorId})")
	int save(AppearanceDO appearance);
	
	@Update("<script>"+ 
			"update tb_appearance " + 
					"<set>" + 
		            "<if test=\"appearanceId != null\">`appearance_id` = #{appearanceId}, </if>" + 
                    "<if test=\"productName != null\">`product_name` = #{productName}, </if>" + 
                    "<if test=\"playingTime != null\">`playing_time` = #{playingTime}, </if>" + 
                    "<if test=\"playingNumber != null\">`playing_number` = #{playingNumber}, </if>" + 
                    "<if test=\"playingPrice != null\">`playing_price` = #{playingPrice}, </if>" + 
                    "<if test=\"specification != null\">`specification` = #{specification}, </if>" + 
                    "<if test=\"customerStoreName != null\">`customer_store_name` = #{customerStoreName}, </if>" + 
                    "<if test=\"customerName != null\">`customer_name` = #{customerName}, </if>" + 
                    "<if test=\"customerTelephone != null\">`customer_telephone` = #{customerTelephone}, </if>" + 
                    "<if test=\"inspectionId != null\">`inspection_id` = #{inspectionId}, </if>" + 
                    "<if test=\"operatorId != null\">`operator_id` = #{operatorId}, </if>" + 
          					"</set>" + 
					"where appearance_id = #{appearanceId}"+
			"</script>")
	int update(AppearanceDO appearance);
	
	@Delete("delete from tb_appearance where appearance_id =#{appearanceId}")
	int remove(Integer appearance_id);
	
	@Delete("<script>"+ 
			"delete from tb_appearance where appearance_id in " + 
					"<foreach item=\"appearanceId\" collection=\"array\" open=\"(\" separator=\",\" close=\")\">" + 
						"#{appearanceId}" + 
					"</foreach>"+
			"</script>")
	int batchRemove(Integer[] appearanceIds);
}
